using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Wrath.RuleForge
{
    public partial class ModuleInformationEntry : Form
    {
        private Globals.ModuleInformation moduleInformation;
        internal Globals.ModuleInformation ModuleInfo 
        { 
            get { return moduleInformation; } 
            set { 
                moduleInformation = new Globals.ModuleInformation(value.Filename, value.Name, value.Author, value.RuleSet, value.Category, value.Thumbnail); 
            } 
        }

        public ModuleInformationEntry()
        {
            InitializeComponent();
            
            // Populate RuleSet dropdown
            comboBoxRuleSet.Items.Clear();
            for (int i = 0; i < Globals.RuleSets.Count; i++)
            {
                comboBoxRuleSet.Items.Add(Globals.RuleSets.GetRuleSet(i));
            }
        }

        private void comboBoxRuleSet_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBoxRuleSet.Text = (string)comboBoxRuleSet.SelectedItem;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            moduleInformation.Name = textBoxName.Text;
            moduleInformation.Author = textBoxAuthor.Text;
            moduleInformation.RuleSet = textBoxRuleSet.Text;
            moduleInformation.Category = textBoxCategory.Text;
            moduleInformation.Thumbnail = thumbnail.Image;

            DialogResult = DialogResult.OK;
            Close();
        }

        private void ModuleInformationEntry_Shown(object sender, EventArgs e)
        {
            if (moduleInformation != null)
            {
                textBoxName.Text = moduleInformation.Name;
                
                textBoxAuthor.Text = moduleInformation.Author;
                
                textBoxRuleSet.Text = moduleInformation.RuleSet;
                comboBoxRuleSet.SelectedItem = moduleInformation.RuleSet;

                textBoxCategory.Text = moduleInformation.Category;

                thumbnail.Image = new Bitmap(moduleInformation.Thumbnail, 76, 86);
            }
        }

        private void thumbnail_Click(object sender, EventArgs e)
        {
            DialogResult result = openThumbnailDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                Image newThumbnail = new Bitmap(Image.FromFile(openThumbnailDialog.FileName), 76, 86);
                thumbnail.Image = newThumbnail;
            }
        }
    }
}